package com.zyh.counselor.service.impl;

import java.util.List;
import java.util.Objects;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyh.common.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zyh.counselor.mapper.CounselorMapper;
import com.zyh.counselor.domain.Counselor;
import com.zyh.counselor.service.ICounselorService;

/**
 * 咨询师信息Service业务层处理
 *
 * @author zhangyangheng
 * @date 2025-03-16
 */
@Service
public class CounselorServiceImpl extends ServiceImpl<CounselorMapper, Counselor> implements ICounselorService {
    public static final Logger log = LoggerFactory.getLogger(CounselorServiceImpl.class);

    @Autowired
    private CounselorMapper counselorMapper;

    /**
     * 查询咨询师信息
     *
     * @param counselorId 咨询师信息主键
     * @return 咨询师信息
     */
    @Override
    public Counselor selectCounselorByCounselorId(Long counselorId) {
        return counselorMapper.selectCounselorByCounselorId(counselorId);
    }

    /**
     * 查询咨询师信息列表
     *
     * @param counselor 咨询师信息
     * @return 咨询师信息
     */
    @Override
    public List<Counselor> selectCounselorList(Counselor counselor) {
        return counselorMapper.selectCounselorList(counselor);
    }

    /**
     * 新增咨询师信息
     *
     * @param counselor 咨询师信息
     * @return 结果
     */
    @Override
    public int insertCounselor(Counselor counselor) {
        counselor.setCreateTime(DateUtils.getNowDate());
        return counselorMapper.insertCounselor(counselor);
    }

    /**
     * 修改咨询师信息
     *
     * @param counselor 咨询师信息
     * @return 结果
     */
    @Override
    public int updateCounselor(Counselor counselor) {
        counselor.setUpdateTime(DateUtils.getNowDate());
        return counselorMapper.updateCounselor(counselor);
    }

    /**
     * 批量删除咨询师信息
     *
     * @param counselorIds 需要删除的咨询师信息主键
     * @return 结果
     */
    @Override
    public int deleteCounselorByCounselorIds(Long[] counselorIds) {
        return counselorMapper.deleteCounselorByCounselorIds(counselorIds);
    }

    /**
     * 删除咨询师信息信息
     *
     * @param counselorId 咨询师信息主键
     * @return 结果
     */
    @Override
    public int deleteCounselorByCounselorId(Long counselorId) {
        return counselorMapper.deleteCounselorByCounselorId(counselorId);
    }

    @Override
    public boolean isCounselor(Long userId) {
        log.info("查询用户是否为咨询师，userId={}", userId);
        return Objects.nonNull(this.getById(userId));
    }
}
